package cn.edu.scau.cmi.tancuier.client;

import java.util.Arrays;
import java.util.List;

import cn.edu.scau.cmi.tancuier.abstractFactory.domainMeat.ConsumerMeatProduct;
import cn.edu.scau.cmi.tancuier.abstractFactory.factory.AbstractFactory;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class AbstractFactoryClient extends Application{

	public static void main(String[] args) {
		Application.launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		primaryStage.setTitle("Abstract Factory");
		
		FlowPane flowPane = new FlowPane();
		flowPane.setPadding(new Insets(10, 20, 10, 20));
		flowPane.setHgap(5);
		flowPane.setVgap(5);
		
		Label guide = new Label("Please choose the meat that you want to produce: ");
		flowPane.getChildren().add(guide);
		
		List<String> brandList = Arrays.asList("Wens","Tianbang","Aonong");
		ObservableList<String> brandObList = FXCollections.observableArrayList(brandList);
		ComboBox<String> brandBox = new ComboBox<String>(brandObList);
		brandBox.getSelectionModel().select(0);
		brandBox.setEditable(false);
		flowPane.getChildren().add(brandBox);
		
		List<String> meatList = Arrays.asList("Beef","Pork","Chicken");
		ObservableList<String> meatObList = FXCollections.observableArrayList(meatList);
		ComboBox<String> meatBox = new ComboBox<String>(meatObList);
		meatBox.getSelectionModel().select(0);
		meatBox.setEditable(false);
		flowPane.getChildren().add(meatBox);
		
		Button produce = new Button("Produce");
		produce.setOnAction(e->{
			String brandType = brandBox.getSelectionModel().getSelectedItem().toString();
			String meatType = meatBox.getSelectionModel().getSelectedItem().toString();
			AbstractFactory factory = AbstractFactory.getFactory(brandType);
			ConsumerMeatProduct meat = null;
			if(meatType == "Beef") {
				meat = factory.produceBeef();
			}
			if(meatType == "Pork") {
				meat = factory.producePork();
			}
			if(meatType == "Chicken") {
				meat = factory.produceChicken();
			}
			Label label =  new Label(meat.produce() + "                       ");
			flowPane.getChildren().add(label);
		});
		flowPane.getChildren().add(produce);
		
		Scene scene = new Scene(flowPane, 600, 300);
		primaryStage.setScene(scene);
		primaryStage.show();
	}

}
